package com.yc.demo.d0301;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet(name = "ShowCartServlet", value = "/ShowCartServlet")
public class ShowCartServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        final HttpSession session = request.getSession();
        final Enumeration<String> names = session.getAttributeNames();

        final PrintWriter out = response.getWriter();
        out.printf("<ul>");

        while (names.hasMoreElements()){
            final String name = names.nextElement();
            out.printf("<li> %s : %d</li>",name,session.getAttribute(name));
        }
        out.printf("</ul>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
